<template>
	<view>
		<view class="cu-bar bg-white solid-bottom" style="border: #EEEEEE 2px solid;">
			<view class="action">
				<text class="cuIcon-titles text-orange"></text>当前分类:{{name}}
			</view>
		</view>
		<view class="cu-card case" :class="isCard?'no-card':''" v-for="item in activityList" :key="item.id">
			<view class="cu-item shadow" @tap="todetail(item.id,item.userId)">
				<view class="image" style="height: 300px;">
					<image :src="item.ai[0].url"
					 mode="aspectFill" style="height: 300px;"></image>
					<view class="cu-bar bg-shadeBottom"> <text class="text-cut">{{item.activityDesc}}</text></view>
				</view>
				<view class="cu-list menu-avatar">
					<view class="cu-item">
						<view class="cu-avatar round lg" style="background-image:url(https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png);"></view>
						<view class="content flex-sub">
							<view class="text-grey">{{'名称:'+item.activityName}}</view>
							<view class="text-gray text-sm flex justify-between">
								{{item.activityDate}}
								<view class="text-gray text-sm">
									参与情况：{{item.tookNumber + '/' + item.limitNumber}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="this.activityList.length == 0" 
		style="text-align: center;vertical-align: middle;padding-top: 20px;font-size: 18px;">
			<text>该分类暂时还没有活动啦</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				name: '',
				activityList: '',
				isCard: false,
				userId: ''
			}
		},
		onLoad(option) {
			this.name = option.name
			this.id = option.categoryId
			uni.startPullDownRefresh();
			this.getlist()
			this.getCookies()
		},
		onPullDownRefresh() {
			this.getlist()
			this.getCookies()
		    setTimeout(function () {
		        uni.stopPullDownRefresh();
		    }, 1000);
		},
		methods: {
			todetail(activityid,userID) {
				let ismine
				if(userID == this.userId) {
					ismine = true
					uni.navigateTo({
						url: '../activitydeatil/activitydeatil?activityid='+activityid+'&ismine='+ismine,
					    success: res => {}
					});
				}else{
					ismine = false
					uni.navigateTo({
						url: '../activitydeatil/activitydeatil?activityid='+activityid+'&ismine='+ismine,
					    success: res => {}
					});
				}
				
			},
			getCookies() {
			  if (document.cookie.length > 0) {
			    var arr = document.cookie.split("; "); //这里显示的格式需要切割一下自己可输出看下
			    for (var i = 0; i < arr.length; i++) {
			      var arr2 = arr[i].split("="); //再次切割
			      //判断查找相对应的值
				  if (arr2[0] == "id") {
				    this.userId = arr2[1]; //保存到保存数据的地方
				  }
			    }
			  }
			},
			getlist() {
				let that= this
				let id = that.id*1
				uni.request({
					url: 'http://101.37.15.60:8080/activity/selectByCategoryId',
					data: {
						categoryId: id
					},
					success: (res) => {
					    if(res.data.message == 'SUCCESS') {
							that.activityList = res.data.data
							for(let i = 0;i<res.data.data.length;i++){
							  let time = res.data.data[i].activityDate
							  let arrTime = []
							  arrTime = time.split(' ')
							  let newTime = arrTime[0]
							  that.activityList[i].activityDate = newTime
							}
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>
